package com.ido.babyshow.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ido.babyshow.dao.ISecCatalogDao;
import com.ido.babyshow.model.SecCatalog;
import com.ido.babyshow.service.IPhotoService;
import com.ido.babyshow.service.ISecCatalogService;

@Service
public class SecCatalogService implements ISecCatalogService
{
   @Resource
   private ISecCatalogDao secCatalogDao;
   
   @Resource
   private IPhotoService photoService;

    public void setCatalogDao(ISecCatalogDao secCatalogDao)
    {
        this.secCatalogDao = secCatalogDao;
    }
 
    @Override
    public Map<Integer,List<SecCatalog>> selectList()
    {
        Map<Integer,List<SecCatalog>> catalogMap=new HashMap<Integer,List<SecCatalog>>();
       List<SecCatalog> secCatalogList= secCatalogDao.<SecCatalog> selectList(null);
       for(SecCatalog secCatalog:secCatalogList){
           int catalogId=secCatalog.getCatalogId();
           secCatalog.setShowPhotos(photoService.selForShow(secCatalog.getId()));
          List<SecCatalog> oneCatalogList=catalogMap.get(catalogId);
          if(oneCatalogList==null){
              oneCatalogList=new ArrayList<SecCatalog>();
          }
          oneCatalogList.add(secCatalog);
          catalogMap.put(catalogId, oneCatalogList);
       }
       return catalogMap;
    }
   
}
